using GraphQL.Types;

namespace GraphQL.Introspection;

/// <summary>
/// The <see cref="__AppliedDirective"/> introspection type represents
/// a directive applied to a schema element - type, field, argument, etc.
/// </summary>
public class __AppliedDirective : ObjectGraphType<AppliedDirective>
{
    /// <summary>
    /// Initializes a new instance of this graph type.
    /// </summary>
    public __AppliedDirective()
    {
        SetName(nameof(__AppliedDirective), validate: false);

        Description =
            "Directive applied to a schema element";

        Field<NonNullGraphType<StringGraphType>>("name")
            .Description("Directive name")
            .ResolveNoAccessor(context => context.Source!.Name);

        Field<NonNullGraphType<ListGraphType<NonNullGraphType<__DirectiveArgument>>>>("args")
            .Description("Values of explicitly specified directive arguments")
            .ResolveNoAccessor(context => context.Source!.List ?? Enumerable.Empty<DirectiveArgument>());
    }
}
